package com.dk.service.impl;

import com.dk.mapper.CarMapper;
import com.dk.pojo.Car;
import com.dk.pojo.vo.CarVO;
import com.dk.service.CarService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;


import java.util.List;

@Service
public class CarServiceImpl implements CarService {
    @Autowired
    private CarMapper carMapper;


    @Override
    public PageInfo<CarVO> getCarAllInfo(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<CarVO> list = carMapper.getCarAllInfo();
        PageInfo<CarVO> page = new PageInfo<>(list);
        return page;
    }

    @Override
    public void addCar(Car c) {
        carMapper.insertSelective(c);
    }

    @Override
    public Car getCarById(Integer carId) {
        return carMapper.selectByPrimaryKey(carId);
    }

    @Override
    public void updateCar(Car c) {
        carMapper.updateByPrimaryKeySelective(c);
    }

    @Override
    public void deleteCar(Integer carId) {
        carMapper.deleteByPrimaryKey(carId);
    }

    @Override
    public List<CarVO> getNoExamineCarInfo() {
        return carMapper.getNoExamineCarInfo();
    }

    @Override
    public void updateCarIsLowerById(Integer carId, Integer flag) {
        Car c = new Car();
        c.setCarId(carId);
        if(flag == 1){
            c.setIsLower(1);
        }else{
            c.setIsLower(0);
        }
        carMapper.updateByPrimaryKeySelective(c);
    }
}
